/**
 * Created by oneminute on 8/29/14.
 */

var lz = require("../../lib/utils/modules")();
var amqp = require("amqp");

var connection = amqp.createConnection(lz.Config.rabbit.server, {
    reconnect: false
});

connection.on("ready", function (_err) {
    if (_err) {
        lz.Logger.error("Connect error: ", _err);
        proccess.exit(1);
        return;
    }

    var exchangeOpts = {
        passive: false
    };
    try {
        var exchange = connection.exchange(lz.Config.rabbit.log.exchange, exchangeOpts, function (_exchange) {
            lz.Logger.info("open exchange.");
            process.exit(0);
        });
        lz.Logger.info("exchange ", exchange.name);
    } catch (e) {
        lz.Logger.info("exchange error : ", e.message);
    }
});

process.on("exit", function() {
    connection.disconnect();
});
